package com.abc.service.impl;

import com.abc.dao.ProductDAO;
import com.abc.entity.Product;
import com.abc.service.ProductService;
import com.abc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class ProductServiceImpl implements ProductService {
    @Autowired
    private ProductDAO productDAO;

    @Override
    public List<Product> findAll() {
        return productDAO.findAll();
    }

    @Override
    public void save(Product product) {
        product.setpNum(1); // 默认1本
        product.setRentType("1"); // 默认可预约
        productDAO.save(product);
    }

    @Override
    public void delete(Integer id) {
        productDAO.delete(id);
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS) // 支持事务
    public Product find(String id) {
        return productDAO.find(id);
    }

    @Override
    public void update(Product product) {
        productDAO.update(product);
    }
}
